import './assets/main.scss';

// 导入所有 element 样式
import 'element-plus/dist/index.css';

import { createApp } from 'vue';
import { createPinia } from 'pinia';
import ElementPlus from 'element-plus';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import App from './App.vue';
import router from './router';
import { setupRouterGuard } from './router/guard';
import { tryLoadUserInfoFromBrowser } from './utils/user-cache';
import { configNProgress } from './utils/nprogress';

const app = createApp(App);

// 注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

app.use(createPinia());
app.use(router);

// 配置页面加载进度条
configNProgress();
// 加载用户缓存信息
tryLoadUserInfoFromBrowser();
// 设置路由守卫
setupRouterGuard(router);

// 使用 Element 组件
app.use(ElementPlus);

app.mount('#app');
